#include "home.h"
#include "ui_home.h"
#include "reservehome.h"
#include "reservecheck.h"
#include "login.h"
#include<QMouseEvent>
#include<QMessageBox>
#include"bookmanage.h"
#include"information_change.h"
#include"reminds.h"
#include"appealcheck.h"

home::home(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::home)
{
    ui->setupUi(this);
    this->resize(600,800);
    this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗口无边框
    connect(ui->pushButton_11,&QPushButton::clicked,this,[this](){
        this->close();
        RecordBooks*rb=new RecordBooks();
        rb->show();
    });
}

home::~home()
{
    delete ui;
}

void home::on_pushButton_clicked()
{
    if(reserveHome::isRemindShowAgain){
        reminds::isFromHome = false;
        reminds* a = new reminds;
        a->show();
    }else{
        reserveHome*r=new reserveHome;
        r->show();
    }
    this->close();
    ui->label_5->setText("姓名：张三");
}

void home::on_pushButton_2_clicked()
{

    //点击跳转到图书借阅部分
    BookManage *bookmanage=new BookManage;
    bookmanage->show();
    this->close();


}
void home::mousePressEvent(QMouseEvent *event) {
    if (event->button() == Qt::LeftButton) {
                initialMousePosition = event->globalPos(); // 记录鼠标按下时的全局位置
                isDragging = true; // 开始拖动
            }
    }

void home::mouseMoveEvent(QMouseEvent *event){
    if (isDragging && event->buttons() & Qt::LeftButton) {
                QPoint delta = event->globalPos() - initialMousePosition; // 计算鼠标移动的距离
                move(x() + delta.x(), y() + delta.y()); // 根据鼠标移动的距离来移动窗口
                initialMousePosition = event->globalPos(); // 更新鼠标位置
            }
    }
void home::mouseReleaseEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            isDragging = false; // 结束拖动
        }
    }

void home::on_pushButton_10_clicked()
{
    this->close();
    reservecheck *r = new reservecheck;
    r->show();
}

void home::on_pushButton_3_clicked()
{
    // 创建一个 QMessageBox 对象
    QMessageBox messageBox;

    // 设置消息框的标题
    messageBox.setWindowTitle("提示");

    // 设置消息框的内容
    messageBox.setText("您确定要退出登录吗？");

    // 设置消息框中的按钮
    messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);

    // 设置消息框的图标
    messageBox.setIcon(QMessageBox::Question);

    // 显示消息框，并等待用户响应
    int ret = messageBox.exec();

    // 根据用户的选择执行相应的操作
    if (ret == QMessageBox::Yes) {
        // 用户点击了"Yes"按钮，执行退出登录的操作
        this->close();
        login* l = new login;
        l->show();
    } else {

    }
}


void home::on_pushButton_4_clicked()
{

    this->close();
    information_change*m=new information_change;
    m->show();

}

void home::on_pushButton_12_clicked()
{
    reminds::isFromHome = true;
    reminds* a = new reminds;
    a->show();
}

void home::on_pushButton_13_clicked()
{
    appealcheck* a=new appealcheck;
    a->show();
}
